package com.novel.controller;

import com.novel.annotation.ResponseResult;
import com.novel.entiy.Comment;
import com.novel.entiy.dto.CommentDTO;
import com.novel.entiy.dto.CommentPageDTO;
import com.novel.entiy.vo.CommentVO;
import com.novel.service.CommentService;
import com.novel.utils.PageResult;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author tanghao
 * @date 2022/4/8
 */
@ResponseResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/comment")
public class CommentController {

    private final CommentService commentService;

    @ApiOperation("发表评论")
    @PostMapping("/publishComment")
    public void comment(@RequestBody CommentDTO commentDTO) {
        commentService.comment(commentDTO);
    }

    @ApiOperation("评论查询 以及评论下面的两条回复")
    @PostMapping("/getCommentList")
    public PageResult<CommentVO> getCommentList(@RequestBody CommentPageDTO commentPageDTO) {
        return commentService.getCommentList(commentPageDTO);
    }

    @ApiOperation("查看全部回复")
    @GetMapping("/getAllReply/{commentId}")
    public CommentVO getAllReply(@PathVariable Long commentId) {
        return commentService.getAllReply(commentId);
    }

    @ApiOperation("评论点赞 type:0 点赞 1 取消点赞")
    @GetMapping("/commentSupport/{commentId}/{novelId}/{type}")
    public void commentSupport(@PathVariable Long commentId, @PathVariable Long novelId, @PathVariable Integer type) {
        commentService.commentSupport(commentId, novelId, type);
    }

    @ApiOperation("查询自己书籍下的所有评论")
    @PostMapping("/getNovelCommentAll")
    public PageResult<CommentVO> getNovelCommentAll(@RequestBody CommentPageDTO commentPageDTO) {
        return commentService.getNovelCommentAll(commentPageDTO);
    }

    @ApiOperation("删除自己书籍的评论")
    @GetMapping("/delComment/{commentId}")
    public void delComment(@PathVariable Long commentId) {
        commentService.delComment(commentId);
    }
}
